const express = require('express')
const path = require("path")
const cors = require('cors')
const app = express()
const bodyParser = require("body-parser");
const appConfig = require(path.resolve(__dirname,'./config/setting.js'))
const requireContext = require("./config/requireContext");

// 解析json形式的数据
app.use(bodyParser.json());
// 解析 application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: false }));
appConfig.cors && app.use(cors())
//挂载静态资源
app.use("/static", express.static(path.resolve(__dirname, "/static")));


// 导入路由模块
const routerFileList = requireContext(path.resolve(__dirname,"./router"));
routerFileList.forEach((v) => {
  app.use(`/${v.filename}`, require(`${v.fileUrl}`));
});

app.listen(appConfig.port , () => {
	console.log(`running ${appConfig.host}:${appConfig.port}`);
})
